<script >

import {isEmail} from "@/utils/validate";

export default {
  components: {
  },
  name:"sendEmail",
  data(){
    return{
      form: {},
      option: {
        submitText: "发送测试",
        emptyBtn: false,
        emptyText: "啊啊啊",
        emptyIcon: "close",
        column: [
          {
            label: "收件人",
            span: 24,
            prop: "email",
            type: "input",
            rules: [
              {
                required: true,
                message: "请输入收件人",
                trigger: "blur",
              },
            ],
          },
          {
            label: "发送标题",
            span: 24,
            prop: "title",
            type: "input",
            rules: [
              {
                required: true,
                message: "请输入发送标题",
                trigger: "blur",
              },
            ],
          },
          {
            label: "发送内容",
            span: 24,
            prop: "content",
            type: "textarea",
            minRows: 10,
            placeholder: "请输入发送内容,支持html",
            rules: [
              {
                required: true,
                message: "请输入发送内容",
                trigger: "blur",
              },
            ],
          },
        ]
      }
    }
  },
  methods: {
    sendEmail(form,done){
      // 校验表单
      if (!isEmail(form.email)) {
        this.$message({
          message: "请输入正确的收件人",
          type: "error",
        });
        done();
        return;
      }
      let params = {
        ...form
      }
      console.log(params)
      this.$https("/email-api/send-email","post",params,2,{}).then( res=> {
        done();
        if (res.data.code === 200){
          this.$message({
            message: "发送成功",
            type: "success",
          });
        }
      })
    }
  }

}
</script>

<template>
      <avue-form :option="option"  ref="formData" v-model="form" @submit="sendEmail">
      </avue-form>
</template>

<style scoped>

</style>